<template>
	<!-- 微信登录 -->
	<view>
		<navbar :navigationBarStyle="navigationBarStyle" ></navbar>
		<view class="screen" style="height: 100vh;" :style="'padding-top:' + vuex_phoneLayout.screenPaddingTop + 'px'">
			<view class="flex-center" style="height: 100%;">
				<!-- <button class="default-button" open-type="getPhoneNumber" @getphonenumber="getPhoneNumber"> -->
				<view class="" style="width: 100%;">
					<button class="default-button"  @tap="getUserProfile">
					  <text>一键授权获取头像昵称</text>
					</button>
				</view>
		    
			</view>
		</view>
	</view>
</template>
<script>
export default {
	data() {
		return {
			navigationBarStyle: {
				background: '',
				color: 'black',
				iconText: '注册' //导航栏文字
			},
			phoneNo: '',
			userInfoModel: {
			  "userName": "",
			  "userHead": "",
			  "sex": "",
			  "city": "",
			  "province": "",
			  "country": "",
			  "userTel": "",
			},
			wxGetMes: {      //从微信获取的信息
			  code: '',
			  iv: '',
			  encryptedData: '',
			},
		};
	},
	onLoad() {
		const _this = this
		uni.login({
			success(res) {
			_this.wxGetMes.code = res.code
			}
		})
		this.$u.vuex('vuex_identity',2)
	},
	methods: {
		getUserProfile(e) {
			let that = this
			// 推荐使用wx.getUserProfile获取用户信息，开发者每次通过该接口获取用户个人信息均需用户确认，开发者妥善保管用户快速填写的头像昵称，避免重复弹窗
			wx.getUserProfile({
				desc: '展示个人头像与昵称', // 声明获取用户个人信息后的用途，后续会展示在弹窗中，请谨慎填写
				success: (res) => {
					console.log(res.avatarUrl)
					let pa = {
						"head": res.userInfo.avatarUrl,
						"nickName": res.userInfo.nickName
					}
					that.$u.api.updateUserMes(pa).then(res => {
						uni.showToast({
							title: '用户信息更新成功',
							icon: 'none',
							duration: 1000
						})
						setTimeout(() => {
							uni.reLaunch({
								url: '/pages/sys/home/index'
							});
						}, 500);
					})
				}
			})
		},
	}
};
</script>
<style lang="scss">

</style>
